package com.example.app.components.MyImage

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import com.example.app.R

@Composable
fun MyFitImage(
        painterResourceId: Int,
) {
    val painter: Painter = painterResource(id = painterResourceId) // 替换为你的图片资源
    Box(
        modifier = Modifier
            .fillMaxWidth() // 让 Box 占据父容器的全部宽度
            .aspectRatio(painter.intrinsicSize.width / painter.intrinsicSize.height), // 根据图片的宽高比设置 Box 的比例
        contentAlignment = Alignment.Center // 调整图片在 Box 中的对齐方式
    ) {
        MyImage(
            painter = painter,
            contentDescription = "Sample Image",
            modifier = Modifier.fillMaxSize(), // 让图片填满 Box
            contentScale = ContentScale.Fit, // 设置图片的缩放方式，以使图片完整显示
            alpha = 1.0f, // 设置图片的不透明度
            colorFilter = null // 可选的颜色过滤效果
        )
    }
}